package com.hthy.futures.ui;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.hthy.futures.AppContext;
import com.hthy.futures.R;
import com.hthy.futures.base.CommonAdapter;
import com.hthy.futures.base.CommonViewHolder;
import com.hthy.futures.bean.AppConfigContext;
import com.hthy.futures.bean.Goods;
import com.hthy.futures.inter.ServiceEvent;

import de.greenrobot.event.EventBus;

/**
 * 服务器选择
 * Author:  Mr.bingley
 * Version:
 * Date:  2017/4/18
 */

public class ServiceDialog extends BaseDialog  {
    Context mcontext;

    private ListView mListView;
    private OnServiceTypeItemSelectedListener mServiceTypeListener;
    private CommonAdapter<AppConfigContext.ServerTypeBean> mServiceAdapter;

    public ServiceDialog(Context context) {
        super(context);
        mcontext = context;

    }

    @Override
    protected void initView(View contentView) {
        mListView = (ListView) contentView.findViewById(R.id.listView);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                AppConfigContext.ServerTypeBean selectGoodItem = mServiceAdapter.getItem(position);
                if (mServiceTypeListener != null) {
                    mServiceTypeListener.select(selectGoodItem);
                }
                dismiss();
            }
        });
        contentView.findViewById(R.id.ll_container).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

    }

    @Override
    protected int getContentView() {
        return R.layout.dialog_good_list;
    }

    public void setServiceTypeItemSelectedListener(OnServiceTypeItemSelectedListener serviceTypeItemSelectedListener) {
        this.mServiceTypeListener = serviceTypeItemSelectedListener;
    }

    public void setServiceAdapter(CommonAdapter<AppConfigContext.ServerTypeBean> serviceAdapter) {
        this.mServiceAdapter = serviceAdapter;
        mServiceAdapter.addItem(AppContext.server_type);
        mListView.setAdapter(mServiceAdapter);
    }

    public interface OnServiceTypeItemSelectedListener {
        void select(AppConfigContext.ServerTypeBean selectGoodItem);
    }
}
